home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_ORBit.idb / usr / freeware / include / ORBitutil / thread-safety.h.z / thread-safety.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  1.0 KB  |  37 lines

  1. #ifndef THREAD_SAFETY_H
  2. #define THREAD_SAFETY_H 1
  3.  
  4. #ifdef NOT_REENTRANT
  5.  
  6. #include <pthread.h>
  7.  
  8. #define DEFINE_LOCK(x) pthread_mutex_t x##_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
  9. #define INIT_LOCK(x) /* We use static initialization, see above */
  10. #define GET_LOCK(x) pthread_mutex_lock(&x##_lock)
  11. #define RELEASE_LOCK(x) pthread_mutex_unlock(&x##_lock)
  12. #define PARAM_LOCK(x) pthread_mutex_t x##_lock
  13. #define LOCK_NAME(x) x##_lock
  14. #define EXTERN_LOCK(x) extern pthread_mutex_t x##_lock
  15. extern pthread_key_t thread_data;
  16. #define GET_THREAD_DATA() pthread_getspecific(thread_data)
  17. #define SET_THREAD_DATA(x) pthread_setspecific(thread_data, (x))
  18.  
  19. #else
  20.  
  21. /* stupid work around ANSI & empty semicolons. */
  22. #define DEFINE_LOCK(x)
  23. #define INIT_LOCK(x)
  24. #define GET_LOCK(x)
  25. #define RELEASE_LOCK(x)
  26. #define PARAM_LOCK(x) gpointer x##_lock
  27. #define LOCK_NAME(x) NULL
  28. #define EXTERN_LOCK(x)
  29.  
  30. extern gpointer prog_data;
  31. #define GET_THREAD_DATA() prog_data
  32. #define SET_THREAD_DATA(x) (prog_data = (x))
  33.  
  34. #endif
  35.  
  36. #endif /* THREAD_SAFETY_H */
  37.